import os
import msvcrt
import docx
import pandas as pd

def file_name(file_dir):
    for root, dirs, files in os.walk(file_dir):
        return files

def zhuanhuan(filename):
    file = docx.Document(filename)
    text = ''
    for para in file.paragraphs:

        if str(para.text).strip() == "":
            continue
        else:
            text += (str(para.text).strip())
            text += ("<seg>\n")
    return text

file_dir = os.getcwd()

res = pd.DataFrame(columns=('ID', '标题', '内容'))

files = file_name(file_dir)

for i in range(len(files)):
    if str(files[i]).split(".")[1] != "docx":
        continue
    text = zhuanhuan(files[i])
    res = res.append([{'ID':'ID','标题': '标题','内容': text}], ignore_index=True)

res.to_excel("output.xlsx", index=0)
print("请按任意键退出~")
ord(msvcrt.getch())






